<?php 

class ContentTag{
	public $tag=array(
		'arclist'=>array('block'=>1,'level'=>4),
		'channel'=>array('block'=>1,'level'=>4),
		'pagelist'=>array('block'=>1,'level'=>4),
		'pageshow'=>array('block'=>0,'level'=>4)
		);
	//arclist标签 最新资讯 
	public function _arclist($attr,$content)
	{
		$cid=isset($attr['cid'])?$attr['cid']:'';
		$aid=isset($attr['aid'])?$attr['aid']:'';
		$row=isset($attr['row'])?$attr['row']:10;
		$titlelen=isset($attr['titlelen'])?$attr['titlelen']:20;

		$php=<<<php
		<?php
		\$cid='$cid';
		\$aid='$aid';
		\$db=K('Content');
		if(\$aid)\$db->where("aid in(\$aid)");
		if(\$cid)\$db->where("content.cid in(\$cid)");
		\$data=\$db->where(\$where)->limit($row)->all();
		foreach (\$data as \$field):
			\$field['url']=getContentUrl(\$field);
			\$field['title']=mb_substr(\$field['title'],0,$titlelen,'utf-8');
		?>
php;
		$php.=$content;
		$php.='<?php endforeach;?>';
		return $php;
	}

	//栏目子列表
	public function _channel($attr,$content)
	{
		$cid=$attr['cid'];
		$type=isset($attr['type'])?$attr['type']:'self';
		
		$php=<<<php
		<?php
		\$db=M('category');
		switch ($type) {
			case 'self':
				\$cat=\$db->all($cid);
				\$data=\$db->where("pid=".\$cat['pid'])->all();
				break;
			case 'son':
				\$data=\$db->where("pid=$cid")->all();
				break;
		}
		foreach (\$data as \$field):
			\$field['caturl']=getCategoryUrl(\$field);
		?>
php;
		$php.=$content;
		$php.='<?php endforeach;?>';
		return $php;
	}

	//分页列表
	public function _pagelist($attr,$content)
	{
		$row=isset($attr['row'])?$attr['row']:10;
		$titlelen=isset($attr['titlelen'])?$attr['titlelen']:20;
		$cid=$_GET['cid'];///

		$php=<<<php
		<?php
		\$cid=\$_GET['cid'];
		\$cat= Data::channelList(M('category')->all(),\$cid);
		\$cat=array_keys(\$cat);
		\$cat[]=\$cid;
		\$db=K('Content');
		\$where="content.cid IN(".implode(',', \$cat).")";
		\$page=new Page(\$db->where(\$where)->count(),$row);
		\$data=\$db->where(\$where)->limit(\$page->limit())->all();
		foreach (\$data as \$field):
			\$field['title']=mb_substr(\$field['title'],0,$titlelen,'utf-8');
			\$field['url']=getContentUrl(\$field);//
		?>
php;
//$page->limit() ($page-1)*$row
		$php.=$content;
		$php.='<?php endforeach;?>';
		return $php;
	}
	//显示页码
	public function _pageshow($attr,$content)
	{
		return "<?php echo \$page->show(); ?>";
	}

}

 ?>